package com.alks.common.config.security;

import com.alks.common.config.interceptor.AuthenticateInterceptor;
import com.alks.common.config.interceptor.ResponseSensitiveInterceptor;
import com.alks.common.config.interceptor.ResponseWrapperFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;

/**
 * @author MS
 * @since 2024/11/8下午4:22
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

//    @Autowired
//    private ResponseSensitiveInterceptor responseCacheInterceptor;
//    @Autowired
//    private ResponseWrapperFilter responseWrapperFilter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] swaggerExcludes=new String[]{"/swagger-ui.html","/swagger-resources/**",
                "/webjars/**","/**/doc.html","/user/login/**","/user/updatePassword/**","/user/logout/**","/sdStyle/busMtlDownload",
                "/pad/**","/show/**", "/open/email/send"};
        registry.addInterceptor(authenticateInterceptor())
                .excludePathPatterns(swaggerExcludes)
                .addPathPatterns("/**");
//        registry.addInterceptor(responseCacheInterceptor);
    }

    @Bean(name = "authenticateInterceptor")
    public AuthenticateInterceptor authenticateInterceptor() {
        return new AuthenticateInterceptor();
    }


//    @Bean
//    public FilterRegistrationBean<Filter> registerResponseWrapperFilter() {
//        FilterRegistrationBean<Filter> filterBean = new FilterRegistrationBean<>();
//        filterBean.setFilter(responseWrapperFilter);
//        filterBean.addUrlPatterns("/*");
//        return filterBean;
//    }
}
